// 权限控制
import { getProfileAPI } from './apis/user'
import router from './router'
import { useUserStore } from './stores/user'
// import { asyncRoutes } from "./router/asyncRoutes";


const WHITE_LIST = ['/login', '/404']
// 路由拦截
router.beforeEach(async (to, from, next) => {
  const store = useUserStore()
  // 有token
  if (store.token) {
    next()
    if(!store.profile.roleId){
      const res=await getProfileAPI()
      // console.log('profile res',res);
      store.setProfile(res.data)
    }
  } else {
    // 没有token
    if (WHITE_LIST.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})